package com.gz.service;


import com.gz.entity.User;
import com.gz.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    
    @Autowired
    UserMapper userMapper;
    
    public User selectByUserName(String nickName) throws Exception{
        User u = userMapper.selectByUserName(nickName);
        return u;
    }
    
    /**
     * 判断 账号 是否存在
     * @param nickName
     * @return
     * @throws Exception
     */
    
    public boolean isExistedNickName(String nickName) throws Exception {
        // 查询 账号
        User u = this.selectByUserName(nickName);
        
        // 是否存在的标记
        // 默认是false, 表示默认是不存在
        // u 对象不为空并且 nickName 不是空串的情况下才认为是存在的
        boolean flag = true;
        if(u == null || u.getUserName() == null || u.getUserName().isEmpty()){
            flag = false;
        }
        return flag;
    }
    
    public void insertUser(String username, String password) throws Exception {
        userMapper.insertUser(username, password);
    }
    
}
